//
//  RLMoreActionsPannelVC.swift
//  RaveLand
//
//  Created by zhuxuhong on 2021/4/28.
//  Copyright © 2021 CSLY. All rights reserved.
//
import BWUIKit
import BWListKit
import BWPanelKit
import BWExtensionKit
import UIKit

class RLMoreActionsPannelItemCell: CollectionViewCell {
    @IBOutlet weak var iconIV: UIImageView!
    @IBOutlet weak var titleLb: UILabel!

    override func bwListItemViewConfigure(_ data: Any?, indexPath: IndexPath) {
        guard let data = data as? RLMoreActionType else {
            return
        }
        iconIV.image = data.icon
        titleLb.text = data.title
    }
}

class RLMoreActionsPannelVC: SheetVC {
    @IBOutlet weak var collectionView: CollectionView!
    
    private lazy var listAdapter = BWListAdapter(collectionView: collectionView)
    
    public var items: [RLMoreActionItem] = []
    
    init(items: [RLMoreActionItem]) {
        self.items = items
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func didLoad() {
        super.didLoad()
        
        maskColor = UIColor.red.a1
        collectionView.showsHorizontalScrollIndicator = false
        
        buildListData()
    }
    
    private func buildListData() {
        let cellRID = RLMoreActionsPannelItemCell.RID
        
        listAdapter.data = .init(registers: [
            .init(style: .cell, xib: cellRID)
        ], sections: [
            .init(layout: .init(insets: .with(all: 20), minimumLineSpacing: 10), items: items.map
            { ac in
                .init(reuseId: cellRID, width: 56, height: 80, data: ac.cate, action: .init(didSelectItem: { _ in
                    ac.handler?()
                }))
            })
        ])
    }
}
